package com.boot.config;

import com.boot.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册拦截器");
        String[] arr = {
                "/",
                "/login",
                "/doLogin",
                "/register",
                "/doRegister",
                "/css/**",
                "/images/**",
                "/js/**",
                "/static/**",
                "/fonts/**"};

        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**") //拦截所有请求，包括静态资源文件
                .excludePathPatterns(arr); //放行登录页，登陆操作，静态资源
    }
}
